package com.eight.cloud.generator.utils;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.eight.cloud.mybatisplus.service.BaseService;
import com.eight.cloud.mybatisplus.service.IBaseService;

/**
 * @ClassName: GeneretorUtils
 * @Author: TXC
 * @Date: 2024-11-06 10:20
 **/
public class GeneratorUtils {

    public static void entityStrategyConfig(StrategyConfig.Builder builder, Class<?> clazz) {
        builder.entityBuilder()
                .enableLombok() // 开启lombok模式
                .enableChainModel() // 开启链式调用
                .enableFileOverride() // 开启覆盖已生成文件
                .enableTableFieldAnnotation() // 开启生成实体时生成字段注解
                .superClass(clazz)
                .enableRemoveIsPrefix() // 开启 Boolean 类型字段移除 is 前缀
                .enableActiveRecord()
                .logicDeleteColumnName("deleted")
                .logicDeletePropertyName("deleted")
                .naming(NamingStrategy.underline_to_camel)
                .addSuperEntityColumns("id", "uuid", "create_time", "update_time", "create_by",
                        "update_by", "deleted", "status", "tenant_id", "dept_id")
                .idType(IdType.AUTO)
                .formatFileName("%sEntity").build();
    }

    public static void mapperStrategyConfig(StrategyConfig.Builder builder) {
        builder.mapperBuilder()
                .superClass(BaseMapper.class)
                .enableFileOverride()
                .enableBaseResultMap()
                .formatMapperFileName("%sMapper")
                .formatXmlFileName("%sMapper").build();
    }

    public static void serviceStrategyConfig(StrategyConfig.Builder builder) {
        builder.serviceBuilder()
                .superServiceClass(IBaseService.class)
                .superServiceImplClass(BaseService.class)
                .formatServiceFileName("I%sService")
                .formatServiceImplFileName("%sServiceImpl").build();
    }

    public static void controllerStrategyConfig(StrategyConfig.Builder builder) {
        builder.controllerBuilder()
                .enableRestStyle() // 开启生成@RestController 控制器
                .formatFileName("%sController").build();
    }
}
